﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ReAnimation.MVP.ViewInterfaces;
using ReAnimation.MVP.Presenters;
using ReAnimation.MVP.Presenters.Helpers;
using ReAnimation.Helpers.Common;
using ReAnimation.MVP.Models.Interfaces;

namespace ReAnimation.MVP.Views
{
    public partial class AnimationProjectSettingsView : BaseUserControlView, IAnimationProjectSettingsView
    {
        private IMainModel _mainModel;
        private IAnimationStepSettingsView _animationStepSettingsView;
        private IAnimationStepsView _animationStepsView;
        private AnimationProjectSettingsPresenter _presenter;

        public AnimationProjectSettingsView(IMainModel mainModel,
                                            IAnimationStepSettingsView animationStepSettingsView,
                                            IAnimationStepsView animationStepsView,
                                            AnimationProjectSettingsPresenter presenter)
        {
            _mainModel = mainModel;
            _animationStepSettingsView = animationStepSettingsView;
            _animationStepsView = animationStepsView;
            _presenter = presenter;

            InternalInitializeComponent();

            _mainModel.CurrentAnimationChanged += new EventHandler(_mainModel_CurrentAnimationChanged);

            _presenter.View = this;
        }

        void _mainModel_CurrentAnimationChanged(object sender, EventArgs e)
        {
            if (_mainModel.CurrentAnimation != null)
                animationNameLabel.Text = _mainModel.CurrentAnimation.Name;
            else
                animationNameLabel.Text = "None";
        }

        private void InternalInitializeComponent()
        {
            InitializeComponent();

            using (BatchLayoutChange.For(this))
            {
                var animationStepSettingsControl = _animationStepSettingsView as UserControl;
                animationStepSettingsControl.Dock = DockStyle.Fill;

                leftBaseTableLayout.Controls.Add(animationStepSettingsControl, 1, 1);

                var animationStepsControl = _animationStepsView as UserControl;
                animationStepsControl.Dock = DockStyle.Fill;

                leftBaseTableLayout.Controls.Add(animationStepsControl, 0, 1);
            }
        }

        #region IAnimationProjectSettingsView Members

        public event EventHandler NewAnimation;
        public event EventHandler LoadAnimation;
        public event EventHandler SaveAnimation;
        public event EventHandler Video;

        public bool NewAnimationEnabled
        {
            set
            {
                newAnimationButton.Enabled = value;
            }
        }

        public bool LoadAnimationEnabled
        {
            set
            {
                loadAnimationButton.Enabled = value;
            }
        }

        public bool SaveAnimationEnabled
        {
            set
            {
                saveAnimationButton.Enabled = value;
            }
        }

        public bool AnimationStepSettingsEnabled
        {
            set
            {
                (_animationStepSettingsView as UserControl).Enabled = value;
            }
        }

        public bool AnimationStepsEnabled
        {
            set
            {
                (_animationStepsView as UserControl).Enabled = value;
            }
        }

        public bool VideoEnabled
        {
            set
            {
                videoButton.Enabled = value;
            }
        }

        #endregion

        private void newAnimationButton_Click(object sender, EventArgs e)
        {
            NewAnimation.Throw(sender,e);
        }

        private void saveAnimationButton_Click(object sender, EventArgs e)
        {
            SaveAnimation.Throw(sender, e);
        }

        private void loadAnimationButton_Click(object sender, EventArgs e)
        {
            LoadAnimation.Throw(sender, e);
        }

        private void videoButton_Click(object sender, EventArgs e)
        {
            Video.Throw(sender, e);
        }

        private void saveAnimationButton_Load(object sender, EventArgs e)
        {

        }
    }
}
